<template>
  <div class="UserPage">
    <van-nav-bar
  title="注册"
  left-text=""

  left-arrow
  @click-left="onClickLeft"

/>
  <van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="username"
    label="用户名"
    placeholder="用户名"
    :rules="[{ required: true, message: '请填写用户名' },
     { pattern: /^[\w-]{5,16}$/, message: '用户名必须五位数以上' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="password"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' },
             { pattern: /^[\w-]{6,16}$/, message: '密码必须六位数以上' }
    ]"
  />
  <div style="margin: 16px;">
    <van-button class="bnt"  round block type="primary" native-type="submit">注册</van-button>
  </div>
  <p @click="add">登录账号</p>
</van-form>

  </div>
</template>

<script>

import { Toast } from 'vant'
import { register } from '@/api/user'
export default {

  name: 'UserPage',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {

    async  onSubmit (values) {
      // console.log('submit', values)
      await register(values)
      // console.log(res)
      this.$router.push('/Login')

      // this.username = ''
      // this.password = ''
    },
    add () {
      this.$router.push('/Login')
    },
    onClickLeft () {
      Toast('返回')
    }

  }
}
</script>

<style lang="less" scoped>
.bnt{
  border-radius: 0;

}
p{font-size: 16px;
margin-left: 300px;

}
</style>
